<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="icon" href="__ROOT__/public/lcbook.ico" type="image/x-icon">
    <link rel="stylesheet" href="__ROOT__/public/static/css/common.css">
    <link rel="stylesheet" href="__ROOT__/public/static/css/register.css">
    <link rel="stylesheet" href="__ROOT__/public/static/css/footer.css">
</head>

<body>
    <!-- 头部logo -->
    <div id="header">
        <div class="logo">
            <a href="{:url('index/index')}">
                <img src="__ROOT__/public/static/image/logo.png" alt="">
            </a>
        </div>
    </div>


    <!--  中间-->
    <div id="content">
        <div class="box">
            <form action="{:url('register/doRegister')}" method="post" n="f" onsubmit="return checkForm()">
                <p class="title">注册</p>
                <p>
                    <label for="">用户名</label>
                    <input type="text" placeholder="请输入邮箱" name="email" value="a@163.com">
                    <a id="emailCheck" href="javascript:void(0)" onclick="CheckEmailExit(this)"
                        class="ml12 activate_font">检查email是否已被使用</a>
                    <span id="email_msg" class="ml12 activate_font""></span>
                </p>

                <p>
                    <label for="">密&nbsp;&nbsp;码</label>
                    <input type="password" placeholder="请输入密码" name="passw1">
                    <span id="passw1_msg" class="ml12 activate_font"></span>
                </p>

                <p>
                    <label for="">确认密码</label>
                    <input type="password" placeholder="请输入密码" name="passw2">
                    <span id="passw2_msg" class="ml12 activate_font"></span>
                </p>

                <p class="code">

                    <label for="">验证码</label>
                    <input type="text" class="text" name="code"><span>&emsp;&emsp;&emsp;</span>
                    <a href="{:url('register/register')}">
                        <span style="width:20px;height:20px;">{:captcha_img()}</span></a>
                    <span>&emsp;&emsp;</span>
                </p>

                <p class="jccenter">
                    <button type=submit name=s>注册</button>
                </p>

                <p class="jccenter"><a href="{:url('login/login')}">已有账号，立即登录</a></p>

            </form>
        </div>
    </div>


    <!--  底部-->
    <div id="footer">
        <div>版权所有© Copyright 2020-2020 书瞳　　广东省佛山市南海区华南师范大学</div>
        <div>联系我们：12345678</div>
    </div>

    <script src="__ROOT__/public/static/js/jquery-1.8.3.min.js"></script>
    <script>
        $(function () {
            //1、失去焦点时，激发验证  除了提交的input框外
            $('input:not([name="code"]').each(function () {
                // console.log($(this)[0]);
                $(this).blur(function () {
                    // console.log($(this)[0]);
                    if ($(this).val() == "") { //为空
                        // $('input[name="s"]').attr("disabled", true);
                        if ($(this).attr('name') == 'email') { //电子邮件
                            $("#email_msg").text("email不能为空！");
                            $('#emailCheck').hide();
                        } else if ($(this).attr('name') == 'passw1') { //密码框
                            $("#passw1_msg").text("密码不能为空！");
                        } else { //确认密码
                            $("#passw2_msg").text("确认密码不能为空！");
                        }
                    } else {
                        if ($(this).attr('name') == 'email') { //验证电子邮件
                            let regExp = /^\w+@\w+(\.\w+)+$/;
                            if (!regExp.test($(this).val())) { //匹配失败
                                $("#email_msg").text("email格式不正确！");
                                $('#emailCheck').hide();
                            } else {
                                $("#email_msg").text("");
                                $('#emailCheck').show();
                            }
                        } else if ($(this).attr('name') == 'passw1') { //密码框
                            $("#passw1_msg").text("");
                            // 密码一致 但下面不为空
                            if ($("input[name='passw2']").val() == $("input[name='passw1']")
                                .val()) {
                                if ($("#passw2_msg").text())
                                    $("#passw2_msg").text("");
                            }
                            //密码不一致 但下面为空
                            else {
                                if (!$("#passw2_msg").text())
                                    $("#passw2_msg").text("两次密码输入不一致！");
                            }
                        } else { //确认密码
                            $("#passw2_msg").text("");
                            if ($("input[name='passw2']").val() != $("input[name='passw1']")
                                .val()) {
                                $("#passw2_msg").text("两次密码输入不一致！");
                            }
                        }
                    }
                });
            });
        });

        //验证邮箱是否存在
        /**
            1、先获取当前邮箱
            2、通过ajax发送POST请求
            3、接受响应
         */
        function CheckEmailExit(ele) {
            // console.log($('input[name="email"]').val());
            $.post("checkEmail", {
                email: $('input[name="email"]').val()
            }, function (res) {
                $('#email_msg').text(res);
                $('#emailCheck').hide();
                // console.log(res);
            })

        }
    </script>
</body>

</html>